#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n,c;
	cin >> n >> c;
	vector<int>nums;
	for (int i = 0; i < n; i++) {
		int x;	cin >> x;
		nums.push_back(x);
	}
	sort(nums.begin(), nums.end());
	int count = 0;
	for (int i = 0; i < n; i++) {
		count += upper_bound(nums.begin(), nums.end(), nums[i] + c) - lower_bound(nums.begin(), nums.end(), nums[i] + c);
	}
	cout << count;
	return 0;
}